#include <iostream>
#include <stdio.h>
#include "vft.hpp"

using namespace std;

class Base {
public:
	virtual void f() { cout << "Base::f" << endl; }
	virtual void g() { cout << "Base::g" << endl; }
	virtual void h() { cout << "Base::h" << endl; }
};

class Derive1 : public Base {
	virtual void f1() { cout << "Derive1::f1" << endl; }
	virtual void g1() { cout << "Derive1::g1" << endl; }
	virtual void h1() { cout << "Derive1::h1" << endl; }
};

class Derive2 : public Base {
	virtual void f() { cout << "Derive2::f" << endl; } // 覆盖
	virtual void g1() { cout << "Derive2::g1" << endl; }
	virtual void h1() { cout << "Derive2::h1" << endl; }
};

int
main() {
	// 继承而不覆盖父类中的虚函数
	Base *b1 = new Derive1();
	AccessVFT(b1, 0);
	delete b1;

	// 继承并且覆盖父类中的虚函数，此时是 5 个虚函数，
	// 此时会调用 Derive2::f
	cout << endl << endl;
	Base *b2 = new Derive2();
	AccessVFT(b2, 0);
	delete b2;	
	return 0;
}
